import java.util.Scanner;

public class Demo25 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("t1 等待之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 等待之后");
            }
        });

        Thread t2 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            synchronized (locker) {
                System.out.println("t2 通知之前");
                // 借助 scanner 控制阻塞. 用户输入之前, 都是阻塞状态.
                // scanner.next();
                locker.notify();
                System.out.println("t2 通知之后");
            }
        });

        t2.start();
        Thread.sleep(100);
        t1.start();
    }
}